package com.itheima;

import java.util.ArrayList;
import java.util.Scanner;

public class StuArrayListDemo {
    public static void main(String[] args) {
        ArrayList<Student> als = new ArrayList<Student>();
        Scanner sc = new Scanner(System.in);
        System.out.println("Please input the size of the ArrayList :");
        int len = sc.nextInt();
        for(int i = 0; i < len; i++)
            addStudent(als,i);
        printStudent(als);
    }

    public static void addStudent(ArrayList<Student> als,int i){
        Scanner sc = new Scanner(System.in);
        System.out.println("Please input the name of student " + (i+1) + " :");
        String name = sc.nextLine();
        System.out.println("Please input the age of student " + (i+1) + " :");
        String age = sc.nextLine();
        als.add( new Student(name,age));
    }

    public static void printStudent(ArrayList<Student> als){
        for(int j = 0; j < als.size();j++)
                System.out.println("name: " + als.get(j).getName() +"  age: " + als.get(j).getAge());
        }

}
